//
//  LzwSeaDetailVC.m
//  NewHalfsugar
//
//  Created by 刘志武 on 16/1/5.
//  Copyright © 2016年 刘志武. All rights reserved.
//

#import "LzwSeaDetailVC.h"
#import "Block.h"
#import "LzwSeaDetailCell.h"
#import "LzwSearchWebVC.h"
#import "LzwbaseTableView.h"

@interface LzwSeaDetailVC ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, retain) LzwbaseTableView *mySeaDeTableView;
@property (nonatomic, retain) NSMutableArray *arrayA;

@end

@implementation LzwSeaDetailVC

-(void)dealloc{
    
    [_mySeaDeTableView release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];

    self.navigationItem.title = self.modleSEA.name;
    
    self.mySeaDeTableView = [[LzwbaseTableView alloc]initWithFrame:[[UIScreen mainScreen]bounds] style:UITableViewStylePlain];
    self.mySeaDeTableView.backgroundColor = [UIColor lightGrayColor];
    [self.view addSubview:self.mySeaDeTableView];
    
    self.mySeaDeTableView.delegate = self;
    self.mySeaDeTableView.dataSource = self;
    
    

    [self.mySeaDeTableView registerClass:[LzwSeaDetailCell class] forCellReuseIdentifier:@"cellD"];

    self.arrayA = [NSMutableArray array];
    
    NSMutableString *str = [NSMutableString stringWithFormat:@"http://open3.bantangapp.com/topic/list?app_installtime=1451365479.933367&app_versions=5.1.1&channel_name=appStore&client_id=bt_app_ios&client_secret=9c1e6634ce1c5098e056628cd66a17a5&device_token=c02c60075e7bab110fbdf27e15de3cb61e97360c4ea3545fd8a5936e46c28ccb&oauth_token=a41d3848f43102aa7759c27ba2c0fe8f&os_versions=9.1&page=0&pagesize=20&scene=%@&screensize=640", self.modleSEA.id];
    
 [Block creatingDataTask:str parameters:nil Cookie:nil User_Agent:nil successAFNBlock:^(id resuposeObject) {
     
     NSMutableArray *array = [resuposeObject objectForKey:@"data"];
     
     for (NSMutableDictionary *dict in array) {
         
         LzwSeaDeModle *modleSd = [[LzwSeaDeModle alloc]init];
         
         [modleSd setValuesForKeysWithDictionary:dict];
         
         [self.arrayA addObject:modleSd];
         
         
     }
     [self.mySeaDeTableView reloadData];
 }];

  
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.arrayA.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    LzwSeaDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellD"];
    if (_arrayA.count != 0) {
        LzwSeaDeModle *model = [_arrayA objectAtIndex:indexPath.row];
        cell.modleSeadetail = model;
    }
    
    
    
    return cell;
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    LzwSearchWebVC *SeaVC = [[LzwSearchWebVC alloc]init];
    
    SeaVC.modleW = [self.arrayA objectAtIndex:indexPath.row];
    
    [self.navigationController pushViewController:SeaVC animated:YES];
    
    
    
}


-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 260;
    
}

-(void)setModleSEA:(LzwSearchModle *)modleSEA{
    
    if (_modleSEA != modleSEA) {
        [_modleSEA release];
        _modleSEA = [modleSEA retain];
    }
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
